package action;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import vo.Cart;
import biz.CartBiz;

public class DogCartListAction implements DogAction {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		CartBiz cartBiz = new CartBiz();
		ArrayList<Cart> cartlist = cartBiz.getCartList(request);
		int totalMoney = 0;
		if(cartlist != null){
			for(int i=0; i<cartlist.size(); i++){
				int money = 
						cartlist.get(i).getPrice() * cartlist.get(i).getQty();
				totalMoney += money;
			}//for
			request.setAttribute("totalMoney", totalMoney);
			request.setAttribute("cartlist", cartlist);
		}//if
		RequestDispatcher dis = 
				request.getRequestDispatcher("./dogCartList.jsp");
		try {
			dis.forward(request, response);
		} catch (ServletException | IOException e) {
			e.printStackTrace();
		}//try~catch
	}//exe
}//class
